<template>
  <div class="app-container">
    <el-row type="flex" align="center" :gutter="20">
      <el-form class="filterData-block" label-position="left" :inline="true" label-width="auto">
        <el-form-item label="关键字:">
          <el-input
            placeholder="名称"
            v-model="filterData.name"
            maxlength="20"
            size="small"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button size="small" icon="el-icon-search" type="primary" @click="refreshTable">搜索</el-button>
        </el-form-item>
        <el-form-item>
          <el-button size="small" icon="el-icon-plus" type="primary" @click="openDetail(null,0)">添加基地</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-row style="margin-top: 20px">
      <el-table v-loading="tableConf.loading" :stripe="true" :border="true" :data="tableData">
        <el-table-column align="center" width="50px" prop="id" label="ID"/>
        <el-table-column align="center" min-width="60px" prop="baseName" label="名称"/>
        <el-table-column align="center" min-width="60px" prop="crtTime" label="创建时间"/>
        <el-table-column align="center" width="500px" label="操作">
          <template slot-scope="{row}">
            <el-button size="mini" icon="el-icon-edit-outline" type="primary"  @click="openDetail(row.id,0)">编辑
            </el-button>
            <el-button size="mini" icon="el-icon-document" type="primary"  @click="openDetail(row.id,1)">基地情况介绍
            </el-button>
            <el-button size="mini" icon="el-icon-document" type="primary"  @click="openDetail(row.id,2)">基地管理办法
            </el-button>
            <el-button size="mini" icon="el-icon-document" type="primary"  @click="openDetail(row.id,3)">基地列表
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-row>

    <el-dialog width="50%"  v-if="visible[0]" :visible.sync="visible[0]" title="添加/编辑" :close-on-click-modal="false"
               :close-on-press-escape="false" :destroy-on-close="true"
    >
      <BaseDetail ref="detail" :id="detailId" :closeDialog="closeDialog"></BaseDetail>
      <span slot="footer" class="dialog-footer">
        <el-button plain type="primary" @click="visible[0] = false">取 消</el-button>
        <el-button type="primary" class="primary" @click="$refs.detail.submit()">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog width="50%"  v-if="visible[1]" :visible.sync="visible[1]" title="地情况介绍" :close-on-click-modal="false"
               :close-on-press-escape="false" :destroy-on-close="true"
    >
      <BaseDataDetail ref="detail" :id="detailId"  :closeDialog="closeDialog"></BaseDataDetail>
      <span slot="footer" class="dialog-footer">
        <el-button plain type="primary" @click="visible[1] = false">取 消</el-button>
        <el-button type="primary" class="primary" @click="$refs.detail.submit()">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog width="50%"  v-if="visible[2]" :visible.sync="visible[2]" title="添加/编辑" :close-on-click-modal="false"
               :close-on-press-escape="false" :destroy-on-close="true"
    >
      <BaseRegulationsDetail ref="detail" :id="detailId"  :closeDialog="closeDialog"></BaseRegulationsDetail>
      <span slot="footer" class="dialog-footer">
        <el-button plain type="primary" @click="visible[2] = false">取 消</el-button>
        <el-button type="primary" class="primary" @click="$refs.detail.submit()">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog width="50%"  v-if="visible[3]" :visible.sync="visible[3]" title="列表" :close-on-click-modal="false"
               :close-on-press-escape="false" :destroy-on-close="true"
    >
      <BaseListDetail ref="detail" :id="detailId" :closeDialog="closeDialog"></BaseListDetail>
      <span slot="footer" class="dialog-footer">
      </span>
    </el-dialog>
  </div>
</template>

<script>
import BaseDetail from '@/components/Entrepreneurship/BaseDetail'
import BaseDataDetail from '@/components/Entrepreneurship/BaseDataDetail'
import BaseRegulationsDetail from '@/components/Entrepreneurship/BaseRegulationsDetail'
import BaseListDetail from '@/components/Entrepreneurship/BaseListDetail'
import {delBsIncubatorsApi, getAreaBaseListApi} from "@/api/entrepreneurship";


export default {
  components: { BaseDetail,BaseDataDetail,BaseRegulationsDetail,BaseListDetail },
  data() {
    return {
      tableData: [],
      tableConf: {
        loading: false
      },
      visible: {//控制弹窗显示
        0: false,
        1: false,
        2: false,
        3: false
      },
      detailId: null,
      filterData: {
        name: '',
      },
      time:[],
      placeTypeLoading: true,

    }
  },
  mounted() {
    this.getTableList()
  },
  methods: {
    downloadCode(url) {
      window.open(url)
    },
    openRecord(id) {
      //新标签页打开列表
      this.$router.push({
        name: 'Major',
        query: {
          id: id
        }
      })
    },
    //打开添加/编辑页
    openDetail(id = null,index) {
      this.detailId = id
      this.visible[index] = true
    },
    //关闭指定弹窗并刷新页面
    closeDialog(index) {
      this.visible[index] = false
      this.getTableList()
    },
    del(id){
      this.$confirm('确定删除该基地吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(()=>{
        delBsIncubatorsApi({id}).then((res)=>{
          this.$message.success('删除成功');
          this.getTableList()
        })
      })
    },
    //获取列表
    getTableList() {
      this.tableConf.loading = true
      const form=JSON.parse(JSON.stringify(this.filterData));
      getAreaBaseListApi(form).then((res) => {
        this.tableData = res
      }).finally(() => {
        this.tableConf.loading = false
      })
    },
    refreshTable() {
      this.getTableList()
    }
  }
}
</script>
<style lang="scss" scoped>
.filterData-block {
  .el-form-item {
    margin-bottom: 0;
  }
}
</style>
